package com.da.javatest.service;

import java.beans.Transient;

import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @Author: chenlida
 * @Date: 2018/11/16 16:20
 * @Description: 测试异步方法失效
 */
@Service
public class AsyncAopServiceImpl implements AsyncAopService {
    //@Autowired
    //private AsyncAopService service = (AsyncAopService)AopContext.currentProxy();

    @Transient
    @Override
    public void addOrder() {
        //AsyncAopService service = (AsyncAopService)AopContext.currentProxy();
        System.out.println("添加成功");
        //service.sendMsg();
        sendMsg();
    }

    @Async
    @Override
    public void sendMsg() {
        try {
            Thread thread = Thread.currentThread();
            //停留3秒
            Thread.sleep(3000);
            String currentThreadName = thread.getName();
            System.out.println(currentThreadName + ":发送消息成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
